import { defineStore } from 'pinia'

export const useCounterStore = defineStore('counter', {
  // 状态（state）
  state: () => ({
    count: 0,
    name: 'Counter',
  }),

  // 计算属性（getters）
  getters: {
    doubleCount: (state) => state.count * 2,
    uppercaseName: (state) => state.name.toUpperCase(),
  },

  // 方法（actions）
  actions: {
    increment() {
      this.count++
    },
    decrement() {
      this.count--
    },
    reset() {
      this.count = 0
    },
    setCount(value) {
      this.count = value
    },
  },
})
